package com.itheima.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itheima.crm.dao.CustomerDao;
import com.itheima.crm.pojo.Customer;
import com.itheima.crm.pojo.QueryVo;
import com.itheima.crm.service.CustomerService;
import com.itheima.crm.utils.Page;

/**
 * 客户处理Service
 * <p>Title: CustomerServiceImpl</p>
 * <p>Description: </p>
 * <p>Company: www.itcast.cn</p> 
 * @version 1.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {

	@Autowired
	private CustomerDao customerDao;
	
	@Override
	public Page<Customer> getCustList(QueryVo queryVo) {
		//计算起始记录
		queryVo.setStart((queryVo.getPage() - 1) * queryVo.getRows());
		//查询客户列表
		List<Customer> custList = customerDao.getCustList(queryVo);
		Page<Customer> page = new Page<Customer>();
		//设置客户列表
		page.setRows(custList);
		page.setPage(queryVo.getPage());
		page.setSize(queryVo.getRows());
		//计算查询总记录数
		int total = customerDao.getCustListCount(queryVo);
		page.setTotal(total);
		return page;
	}

	@Override
	public Customer getCustomerById(long custId) {
		Customer customer = customerDao.getCustomerById(custId);
		return customer;
	}

	@Override
	public void updateCustomerById(Customer customer) {
		customerDao.updateCustomerById(customer);
	}

}
